package Test;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TimeStamp {
    public static long getTimeStamp(String time, String zone, String formate) throws Exception {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formate);
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatter);
        ZoneId zoneId = ZoneId.of(zone);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        return date.getTime();
    }

    public static long getTimeStamp2(String time, String zone, String formate) throws Exception {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formate);
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatter);
        ZoneId zoneId = ZoneId.of(zone);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        return zdt.toInstant().toEpochMilli();
    }

    public static long getDefaultTimeStamp(String time, String zone) throws Exception {
        String defaultFormat = "yyyy-MM-dd HH:mm:ss";
        return getTimeStamp(time, zone, defaultFormat);
    }


    public static void main(String[] args) {
        try {
            long result = getTimeStamp("2018-01-08 11:00:00", "UTC+10:00", "yyyy-MM-dd HH:mm:ss");
            long result2 = getTimeStamp2("2018-01-08 11:00:00", "UTC+10:00", "yyyy-MM-dd HH:mm:ss");
            System.out.println(result);
            System.out.println(result2);
        } catch (Exception e) {
            System.out.println(e.getStackTrace());
        }
    }
}
